/******************************************************************************
 *                                                                            *
 *               (c) 2008-2009 HutLab. All rights reserved.                   *
 *                        Eduardo Henrique Leite                              *
 *                                                                            *
 ******************************************************************************

 History:
 Created 05/01/2009

 */

package hutlab.sudoku.engine.ai;

import hutlab.sudoku.engine.base.*;

/**
 *
 */
public class SudokuSearch {

    // ----- FIELDS -----

    private ArrayList mItems;

    // ----- GETTERS -----

    public ArrayList getItems(){
        return mItems;
    }

    // ----- SETTERS -----

    public void setItems(ArrayList items){
        mItems = items;
    }

    // ----- PUBLIC -----

    public void add(int value, int row, int column) {
        SudokuSearchItem item = new SudokuSearchItem();
        item.setColumn(column);
        item.setRow(row);
        item.setValue(value);
        item.setCount(1);

        this.mItems.add(item);
    }

    public void update(int value) {
        SudokuSearchItem item;
        for (int i = 0; i < this.mItems.getCount(); i++) {
            item = (SudokuSearchItem) this.mItems.getElement(i);
            if (item.getValue() == value) {
                 item.setCount(item.getCount() + 1);
            }
        }
    }

    public void clear() {
        this.mItems.clear();
    }

    public boolean contains(int value) {
        SudokuSearchItem item;
        for (int i = 0; i < this.mItems.getCount(); i++){
            item = (SudokuSearchItem) this.mItems.getElement(i);
            if (item.getValue() == value){
                return true;
            }
        }
        return false;
    }

    // ----- CONSTRUCTOR -----

    public SudokuSearch() {
        this.mItems = new ArrayList();
    }

}
